package br.com.dfr.sgc.view.managedbean;

import java.util.List;

import javax.faces.model.ListDataModel;

import org.primefaces.model.SelectableDataModel;

import br.com.dfr.sgc.entity.Solicitacao;

public class SolicitacaoDataModel extends ListDataModel<Solicitacao> implements
		SelectableDataModel<Solicitacao> {

	public SolicitacaoDataModel() {
	}

	public SolicitacaoDataModel(List<Solicitacao> data) {
		super(data);
	}

	@SuppressWarnings("unchecked")
	@Override
	public Solicitacao getRowData(String rowKey) {

		List<Solicitacao> solicitacaos = (List<Solicitacao>) getWrappedData();

		for (Solicitacao solicitacao : solicitacaos) {
			if (solicitacao.getNumeroSolicitacao().equals(rowKey))
				return solicitacao;
		}

		return null;
	}

	@Override
	public Object getRowKey(Solicitacao solicitacao) {
		return solicitacao.getNumeroSolicitacao();
	}
}
